package cn.edu.scau.cmi.zhengweixin.factory;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextArea;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;


public class SimpleFactoryController {

    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private ChoiceBox<String> choiceBox;

    @FXML
    private Button outputButton;

    @FXML
    private TextArea outputTextArea;

    @FXML
    private ImageView photo;

    @FXML
    void output(ActionEvent event) {
    
    	Insurance insurance = null;
    	switch(choiceBox.getSelectionModel().getSelectedIndex()) {
    		case 0:{
    			insurance = SimpleInsuranceFactory.createInsurance(DriverInsurance.class);
    			break;
    		}
    		case 1:{
    			insurance = SimpleInsuranceFactory.createInsurance(CarInsurance.class);
    			break;
    		}
    		case 2:{
    			insurance = SimpleInsuranceFactory.createInsurance(PassengerInsurance.class);
    			break;
    		}
    		case 3:{
    			insurance = SimpleInsuranceFactory.createInsurance(OtherInsurance.class);
    			break;
    		}
    		default:
    			break;
    	}
    	if(null == insurance) {
    		outputTextArea.appendText("请选择保险类型\n");
    	}else {
    		outputTextArea.appendText("class" + insurance.getClass() + ", message:" + insurance.message() + "\n");
    	}
    	
    }

    @FXML
    void selectType(MouseEvent event) {
    	choiceBox.setItems(FXCollections.observableArrayList("司机受伤", "汽车损坏", "人员伤亡", "多种事故"));
    }

    @FXML
    void initialize() {
        assert choiceBox != null : "fx:id=\"choiceBox\" was not injected: check your FXML file 'Factory.fxml'.";
        assert outputButton != null : "fx:id=\"outputButton\" was not injected: check your FXML file 'Factory.fxml'.";
        assert outputTextArea != null : "fx:id=\"outputTextArea\" was not injected: check your FXML file 'Factory.fxml'.";
        assert photo != null : "fx:id=\"photo\" was not injected: check your FXML file 'Factory.fxml'.";
    }

}
